<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of ConfigAction
 *
 * @author Administrator
 */
import('@.Filter.SecurityAction');
import('@.Service.ConfigService');
import('@.Service.SeoService');
import('@.Util.ConstantUtil');
import("@.ORG.Net.Keditor");

class ConfigAction extends SecurityAction {

    function config() {
        $configService = new ConfigService();
        //$configs = $configService->getConfigValues('seo_title,seo_content,seo_key');
        $seoService = new SeoService();
        $seoConfig = $seoService->findSeoByModule(ConstantUtil::$SEO_MODULE[0]);

        $this->assign('seoConfig', $seoConfig);
        $this->assign('mobile_filter_type_name', $configService->getConfigValue('mobile_filter_type_name'));
        
        $ke = new Keditor();
        $ke->id = "config_fooler"; //指定textarea的id
        $ke->form = "frm_config"; //指定form的id，默认为from1
        $ke->afterCreate = "ctrlenter"; //定义创建后执行函数，ctrlenter表示ctrl+enter提交表单。
        $keshow = $ke->show(); //生成js代码
        $this->assign("keshow", $keshow);
        $this->assign('fooler_info_config', $configService->getConfigValue('fooler_info_config'));

        $this->assign('seoModules', ConstantUtil::$SEO_MODULE);
        //$this->assign('configs', $configs);
        $this->assign('content', 'config');
        $this->display('Admin:global');
    }

    function findSeoConfig() {
        $module = $_POST['module'];
        $seoService = new SeoService();
        $seoConfig = $seoService->findSeoByModule($module);

        $this->ajaxReturn($seoConfig);
    }

    function configSave() {
        $mobile_filter_type_name = trim($_POST['mobile_filter_type_name']);

        $configService = new ConfigService();
        $configService->setConfigValue('mobile_filter_type_name', $mobile_filter_type_name);
        
        //页脚信息
        $fooler_info_config = trim($_POST['fooler_info_config']);
        $configService->setConfigValue('fooler_info_config', $fooler_info_config);

        $seo['title'] = trim($_POST['title']);
        $seo['keyword'] = trim($_POST['keyword']);
        $seo['description'] = trim($_POST['description']);
        $seo['module'] = trim($_POST['module']);
        $seoService = new SeoService();
        $seoService->insert($seo);

        $this->redirect('config');
    }

    function websiteConfig() {

        import("@.ORG.Net.Keditor");
        $ke = new Keditor();
        $ke->id = "website_text"; //指定textarea的id
        $ke->form = "frm_config"; //指定form的id，默认为from1
        $ke->afterCreate = "ctrlenter"; //定义创建后执行函数，ctrlenter表示ctrl+enter提交表单。
        $keshow = $ke->show(); //生成js代码
        $this->assign("keshow", $keshow);

        $configService = new ConfigService();

        $listConfig = $configService->getConfigValues('email,qq,fax');

        $demagogic = $configService->getConfig('demagogic');
//        dump($demagogic);return;
        $this->assign("listConfig", $listConfig);
        $this->assign("demagogic", $demagogic);

        $this->assign('content', 'websiteconfig');
        $this->display('Admin:global');
    }

    function websiteConfigSave() {
        $configService = new ConfigService();
        foreach ($_POST as $key => $value) {
            if ('__hash__' == $key) {
                continue;
            }
            $configService->setConfigValue($key, stripslashes($value));
        }

        $this->redirect('websiteConfig');
    }

}

?>
